package supplierconsumer;

public class Consumer extends Thread{
	Container container;

	public Consumer(String name, Container container) {
		super(name);
		this.container = container;
	}

	@Override
	public void run() {
		
		for(int i = 1 ; i <= 5 ; i ++) {
			Dumpling pop = container.pop();
			// 如果唤醒后还没吃到饺子，则减去机会，再此获取
			if (pop == null) {
				i--;
				continue;
			}
			System.out.println(this.getName() + "吃了" + pop.getFilling() +"馅饺子");
			
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
